﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

public partial class Yalie_ExcelImport : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void ButtonImport_Click(object sender, EventArgs e)
    {
        ExcelHandler eh = new ExcelHandler();
        //检查execl是否存在、文件类型是否为excel、上传文件名是否正确
        if (eh.CheckExcel(FileUpload1,"压裂"))
        {
            string filename = System.IO.Path.GetFileNameWithoutExtension(FileUpload1.FileName).ToString().ToLower();
            filename = filename + System.DateTime.Now.ToString("yyyyMMddHHmmss") + ".xls";
            string savePath = Server.MapPath(("~\\upfiles\\") + filename);

            FileUpload1.SaveAs(savePath);//保存excel到服务器

            DataSet ds = eh.ExcelSqlConnection(savePath, filename);

            DBOperator dbo = new DBOperator();
            dbo.ExcelImport(ds,"YL");//Excel导入数据库
            //显示结果
            LabelResult.Text = dbo.ResultMessage;
            LabelInsert.Text = dbo.InsertMessage;
            LabelUpdate.Text = dbo.UpdateMessage;
            LabelFailure.Text = dbo.ErrorMessage;
        }
        else
        {
            LabelResult.Text = eh.CheckMessage;
        }
    }
}